Expand description
This is a crate is made for parsing ANSI escape sequences.
The list of covered sequences.
- Cursor Position
- Cursor {Up, Down, Forward, Backward}
- Cursor {Save, Restore}
- Erase Display
- Erase Line
- Set Graphics mode
- Set/Reset Text Mode
Usage
use ansitok::parse_ansi;
let text = "\x1b[31;1;4mHello World\x1b[0m";
for token in parse_ansi(text) {
let kind = token.kind();
let token_text = &text[token.start()..token.end()];
println!("text={:?} kind={:?}", token_text, kind);
}
Parse SGR.
use ansitok::{parse_ansi, parse_ansi_sgr, Output, ElementKind};
let text = "\x1b[31;1;4mHello World\x1b[0m \x1b[38;2;255;255;0m!!!\x1b[0m";
for token in parse_ansi(text) {
if token.kind() != ElementKind::Sgr {
continue;
}
let sgr = &text[token.start()..token.end()];
for style in parse_ansi_sgr(sgr) {
println!("style={:?}", style);
let style = style.as_escape().unwrap();
println!("style={:?}", style);
}
}
Structs
An ANSI escape sequence parser.
Element indicates a slice position in the string and its type.
Enums
A Color representation in ANSI sequences.
A type of a section in a text with ANSI sequences.
An ANSI Escape Sequence.
The type which represents a result of parsing.
An attribute of Select Graphic Rendition(SGR)
Functions
Creates a parser for ANSI escape sequences.
Creates a parser for Select Graphic Rendition(SGR) sequences.